package com.masterclient.app.modules.firstpager.fragments.adapters;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.masterclient.app.R;
import com.eoner.baselibrary.bean.firstpager.RecommendPagerBean;
import com.eoner.baselibrary.utils.GlideUtil;

import java.util.List;

/**
 * 作者：sean
 * 创建时间：2017/6/13 14:05
 * 功能说明：首页精选专题列表
 */

public class SpecialListAdapter extends BaseAdapter {
    private Context context;
    private List<RecommendPagerBean.DataBean.ShRemCollectionBean.ShCollectionsBean> list;
    private LayoutInflater inflater;

    public SpecialListAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View container, ViewGroup viewGroup) {
        ViewHolder holder;
        if(container == null){
            container = inflater.inflate(R.layout.view_special_item, null);
            holder = new ViewHolder(container);
            container.setTag(holder);
        }else {
            holder = (ViewHolder) container.getTag();
        }
        RecommendPagerBean.DataBean.ShRemCollectionBean.ShCollectionsBean item = list.get(position);
        if(item!=null){
            GlideUtil.displayImage(context,item.getSh_image(),holder.ivSpecial);
//            App.picasso.load(item.getSh_image()).fit().into(holder.ivSpecial);
            if(TextUtils.isEmpty(item.getSh_name())){
                holder.tvSpecialTitle.setVisibility(View.GONE);
            }else {
                holder.tvSpecialTitle.setText(item.getSh_name());
            }
            if(TextUtils.isEmpty(item.getSh_subname())){
                holder.tvSpecialDesc.setVisibility(View.GONE);
            }else {
                holder.tvSpecialDesc.setText(item.getSh_subname());
            }
        }

        return container;
    }

    public void setList(List<RecommendPagerBean.DataBean.ShRemCollectionBean.ShCollectionsBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    private static class ViewHolder {
        ImageView ivSpecial;
        TextView tvSpecialTitle;
        TextView tvSpecialDesc;

        ViewHolder(View view) {
            ivSpecial = (ImageView) view.findViewById(R.id.iv_special);
            tvSpecialTitle = (TextView) view.findViewById(R.id.tv_special_title);
            tvSpecialDesc = (TextView) view.findViewById(R.id.tv_special_desc);
        }
    }
}
